<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Title</title>
</head>
<body>
<ul>
    <li>榴莲</li>
    <li>臭豆腐</li>
    <li>鲱鱼罐头</li>
    <li>大猪蹄子</li>
</ul>
<script>
    function test() {
        function counter() {
            let num = 0;
            return function fn(clear) {
                if (clear) num = 0;
                return ++num;
            }
        }

        const count = counter();
        console.log(count());
        console.log(count());
        console.log(count());
        console.log(count());
        console.log(count());
        console.log(count(true));
        console.log(count());
        console.log(count());
    }

    test();

    const lis = document.querySelectorAll('li');
    lis.forEach((e, i) => {
        e.onclick = () => {
            console.log(i);
        }
    });

</script>
</body>
</html>